﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using WinHBM.Core.Net.Http;
using System.Windows.Forms;
using WinHBM.Core.Bluetooth;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace WinHBM.Core.Net.Sockets.Cmd
{
    public class BluetoothUnBindCmd : SocketCmd
    {
        private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(BluetoothUnBindCmd));
        private HttpClient client = HttpClient.Instance;
        public override void executeCmd(JObject request, FlashSocketServer socket)
        {

            //if (BluetoothClientHolder.bluetoothClient != null)
            //{

                //MagicBar bar = new MagicBar(BluetoothClientHolder.bluetoothClient);
                
            //}

            try
            {
                client.CreateRequest("/api/user-role/unbind-bar", RequestMethod.POST)
            .send((response, json) => {
                UserInfo userinfo = UserInfo.INSTANCE;
                userinfo.Address = null;
                userinfo.commit();
                socket.Send(wrapCmd(CMD_BLUETOOTH_UNBIND, json));
                
            }, (response, exception) => {
                socket.Send(wrapCmd(CMD_BLUETOOTH_UNBIND, "解绑失败"));
            });
            }
            catch (Exception e)
            {
                Logger.Error(e);
                socket.Send(wrapCmd(CMD_BLUETOOTH_UNBIND, e.Message));
            }
            
        }

        
    }
}
